package 线程安全.多线程;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ReadMsg implements Runnable {
    private Socket socket;

    public ReadMsg(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        System.out.println("读取进程启动！");
        try {
            InputStream inputStream = socket.getInputStream();
            int len = 0;
            byte[] bytes = new byte[1024];
            while ((len = inputStream.read(bytes)) != -1) {
                System.out.println("收到的数据:" + new String(bytes, 0, len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
